package com.example.arithmetic.round;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Auther: yaozhiqi
 * @Date: 2021/7/11 22:02
 */
public class ReflectUtil {
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, IllegalAccessException {
        System.out.println(ReflectUtil.methodInvoker("java.lang.String.length()"));
    }
    public static Object methodInvoker(String classMethd) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        int lastIndex = classMethd.lastIndexOf(".");
        String className = classMethd.substring(0, lastIndex);
        String mathod = classMethd.substring(lastIndex+1, classMethd.length()-2);
        Class<?> aClass = Class.forName(className);
        Method declaredMethod = aClass.getDeclaredMethod(mathod);
        return declaredMethod.getDefaultValue();
    }
}
